<template>
  <div>
    <div class="wrap">
      <el-row>
        <el-col span="16">
          <el-menu mode="horizontal">
            <el-submenu class="index-drop" @click.native="">
              <template slot="title">
                <a class="droplink" href="javascript:void(0)">全部服务</a>
              </template>
              <el-menu-item v-for="item in menudata" :index="item.id">
                {{ item.itemType }}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-col>
        <el-col span="8">
          <el-menu mode="horizontal">
            <el-menu-item v-for="item in menudata" :index="item.id">
              {{item.itemType}}
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-row>
    </div>

    <div>
      <el-carousel :interval="4000" type="card" class="carousal">
        <el-carousel-item v-for="item in bannerData" :key="item.id">
          <img :src="item.imgUrl" width="100%" height="100%">
        </el-carousel-item>
      </el-carousel>
    </div>
    <div style=" width: 1200px;align-self: center;height: 100px;font-size: 20px">
      <el-row>
        <el-col span="16">
          <el-card style="width: 100%">
            <i class="el-icon-s-goods"></i>
            <span>平台推荐</span>
          </el-card>

        </el-col>
      </el-row>
    </div>
    <div style="display: flex; justify-content: center; align-items: center">
      <el-row class="" gutter="24">
        <el-col span="6" v-for="p in serviceItemDate" >
          <el-card @click.native="goToDetail(p.id)">
              <img :src="p.url" width="100%" height="500">
            <p style="font-size: 14px;height: 30px">
                {{p.title}}
            </p>
            <p style="font-size: 12px">
              <b>￥{{p.price}}</b> <s>{{p.oldPrice}}</s>
              <span style="float: right">服务量:{{p.saleCount}}</span>
            </p>
          </el-card>

        </el-col>
      </el-row>
    </div>


  </div>
</template>

<script>
export default {
  name: "IndexmainView",
  data() {
    return {
      userId: '',
      menudata: [
        {id: 1, itemType: '分类1'},
        {id: 2, itemType: '分类2'},
        {id: 3, itemType: '分类3'},
      ],
      bannerData: [
        {id: 1, imgUrl: require("../assets/b.png")},
        {id: 2, imgUrl: require("../assets/c.png")},
        {id: 3, imgUrl: require("../assets/d.png")},
      ],
      serviceItemDate: [
        {id: 1, title: '全屋保洁', url: require("../assets/1.jpg"), price: 100, saleCount: 10},
        {id: 2, title: '衣物整理', url: require("../assets/2.jpg"), price: 100, saleCount: 33},
        {id: 3, title: '日常打扫', url: require("../assets/3.jpg"), price: 100, saleCount: 28},
        {id: 4, title: '开荒保洁', url: require("../assets/4.jpg"), price: 200, saleCount: 34},
        {id: 5, title: '衣物归类', url: require("../assets/5.jpg"), price: 456, saleCount: 15},
        {id: 6, title: '服务名', url: require("../assets/6.jpg"), price: 5426, saleCount: 9},
        {id: 7, title: '服务名', url: require("../assets/7.jpg"), price: 564, saleCount: 51},
        {id: 8, title: '服务名', url: require("../assets/8.jpg"), price: 466, saleCount: 18},

      ],
      recommend: [
        {id: 1, itemName: 'test', minPrice: '1', imgUrl: require("../assets/c.png")},
        {id: 2, itemName: 'test', minPrice: '1', imgUrl: require("../assets/d.png")},
        {id: 3, itemName: 'test', minPrice: '1', imgUrl: require("../assets/e.png")},
        {id: 4, itemName: 'test', minPrice: '1', imgUrl: require("../assets/e.png")},

      ],
    };
  },
  methods: {
    goToDetail(id) {
      console.log("点击")
      //加“/”就指定对应路径，不加直接写改的是当前路劲最末未的
      //this.$router.push({ path: 'detail', query: { id: 123 } });
      this.$router.push({ name: 'detail', params: { id: id } });
    },
    loadUser() {

      let url = 'http://localhost:9081/user/'+this.userId;
      console.log('url = ' + url);
      this.axios.get(url).then((response) => {
        let responseBody = response.data;
        console.log(responseBody);
        if (responseBody.state == 20000) {
          this.$message({
            showClose: true,
            message: '查询成功！',
            type: 'success'
          });
          this.user = responseBody.data;
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },

  },
  mounted() {

    console.log("这里");
    this.userId=this.$route.query.userId
    console.log('当前的用户id：',this.userId)
    if (this.userId != null) {
      this.loadUser();
    }
  }
}
</script>

<style scoped>


.wrap {
  width: 1200px;
  align-self: center;
}
.index-content{
   height: 350px;

  /* 这里误设置了高度导致floor溢出，没有撑起应有的高度 footer布局在了tab后*/
}
.index-drop {
  display: inline-block;
  width: 200px;
  display: flex;
  justify-content: center;
  background-color: rgb(51, 49, 49);
}

.droplink {
  color: #fff;
  font-size: 18px;
}

.ivu-col .ivu-menu-item {
  font-size: 16px;
}

.fir-menu .ivu-dropdown-item {
  font-size: 16px !important;
  display: flex;
  justify-content: space-between;
}

.banner-carousal:hover {
  cursor: pointer;
}

.carousal-item {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 400px;
  font-size: 50px;
  color: rebeccapurple;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}

/*********服务展示***********/
.ivu-card-head p {
  height: 80px;
}
.tabs {
  margin-bottom: 50px;
}
.tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tab-item {
  display: flex;
  justify-content: center;
  align-items: center;
}
.tab-item:hover {
  cursor: pointer;
}
.item-img {
  width: 150px;
  height: 200px;
  border: none;
}
.item-itemName,
.item-price {
  width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 10px;
  font-size: 12px;
}
</style>